// 显示所有公告
let showHistoryNotice = () => {
    $.ajax({
        type: 'get',
        url: '/showHistoryNotice',
        data: '',
        success: function (result) {
            let data = template('announce-li', {
                list: result
            })
            $('.history-list').html(data)
        }
    })
}
showHistoryNotice()
// 删除公告
$('.history-list').on('click', '.del', function () {
    if (confirm('确认要删除此公告吗？')) {
        let id = $(this).attr('data-id')
        $.ajax({
            type: 'get',
            url: '/delAnnounce',
            data: {
                id: id
            },
            success: function (result) {
                if (result.msg == '删除成功') {
                    alert(result.msg)
                    location.reload()
                }
            }
        })
    }
})
// 回显公告
$('.history-list').on('click', '.edit', function () {
    let id = $(this).attr('data-id')
    $.ajax({
        type: 'get',
        url: '/getAnnounce',
        data: {
            id: id
        },
        success: function (result) {
            let data = template('changeAnnounce-template', {
                list: result
            })
            $('.change').html(data)
        }
    })
    $('.change').fadeIn()
})
// 点击取消按钮取消回显框
$('.change').on('click', '.cancel-btn', function () {
    $('.change').fadeOut()
    $('#change-form textarea').val('')
})
$('.change').on('click', '.quxiao', function () {
    $('.change').fadeOut()
    $('#change-form textarea').val('')
})

// 更改公告
$('.change').on('click', '.change-btn', function () {
    let id = $(this).attr('data-id')
    let data = $('#change-form').serialize()
    data += '&id=' + id
    $.ajax({
        type: 'post',
        url: '/changeAnnounce',
        data: data,
        success: function (result) {
            if (result.msg == '修改成功') {
                alert(result.msg)
                location.reload()
            }
        }
    })
})